package com.hdoit.kylin.logical.experiment.dao.impl;
import java.util.List;

import org.springframework.stereotype.Component;

import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.pub.YesOrNoInteger;
import com.tennetcn.common.logical.superbase.model.Employee;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;
import com.hdoit.kylin.logical.experiment.dao.IExperimentDao;
import com.hdoit.kylin.logical.experiment.model.Experiment;
import com.hdoit.kylin.logical.group.model.Project;
import com.hdoit.kylin.logical.viewmodel.studentManager.ExperimentSearch;
/**
* @author luozhicheng
* @email
* @createtime 2017年07月18日 20:14:32
* @comment
*/
@Component
public class ExperimentDaoImpl extends SuperDao<Experiment> implements IExperimentDao{
	@Override
	public int queryCount(ExperimentSearch search) {
		IFinderExpression finderExpression = FinderExpressionFactory
				.createExpression();
		finderExpression.addBody("select count(experimentId) from",Experiment.class)
						.leftJoin(Project.class, "project")
						.on("project_experiment.projectId", "project.projectId");
		return queryCount(finderExpression, search);
	}
	
	@Override
	public List<Experiment> queryList(ExperimentSearch search, PagerModel pagerModel){
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("experiment.*","project.projectName as projectName","employee.employeeName as employeeName")
						.from(Experiment.class,"experiment")
						.leftJoin(Project.class, "project")
						.on("experiment.projectId", "project.projectId")
						.leftJoin(Employee.class,"employee")
						.on("experiment.employeeId", "employee.employeeId")
						.andWhere("experiment.deleteMark = 1");
		if(search.getEmployeeIds()!= null && search.getEmployeeIds().size()>0){
			finderExpression.andWhereInString("experiment.employeeId", search.getEmployeeIds());
		}

		return queryList(finderExpression,search,pagerModel);
	}
	@Override
	public List<Experiment> queryListByProjectId(String projectId){
		IFinderExpression finderExpression = FinderExpressionFactory.createExpression();
		finderExpression.select("experiment.*")
						.from(Experiment.class,"experiment")
						.andWhere("experiment.projectId=#{projectId}")
						.setParam("projectId", projectId);
		finderExpression.addOrderInfoList(getOrderInfoList());
		return queryList(finderExpression);
	}
	
	@Override
	public List<Experiment> queryListByEmployeeIds(List<String> employeeIds){
		ExperimentSearch search = new ExperimentSearch();
		search.setDeleteMark(YesOrNoInteger.no);
		search.setEmployeeIds(employeeIds);
		return queryList(search,null);
		
	}
}